package com.ljy.my_study.leetcode.两数之和;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author lijunying
 * @date 2021/9/18 9:15
 */
public class TestMain2 {

    public int[] twoSum(int[] nums, int target) {
        int len=nums.length;
        Map<Integer,Integer> map=new LinkedHashMap<>();
        for(int i=0;i<nums.length;i++){
            int key=nums[i];
            Integer index=map.getOrDefault(key,i);
            int other=target-key;
            if(map.containsKey(other)){
                return new int[]{map.get(other),i};
            }
            map.put(key,index);
        }
        return null;
    }
}
